<?
		function format_date($date){
			global $db;
			$rdate = "";
			$rs = $db->query("select date_format('$date','%d-%m-%Y') as mydate");
			$row = $db->fetch_array($rs);
			$rdate = $row[mydate];
			return $rdate;
		}
		
		function format_date_time($date){
			global $db;
			$rdate = "";
			$rs = $db->query("select date_format('$date','%d-%m-%Y %h:%s') as mydate");
			$row = $db->fetch_array($rs);
			$rdate = $row[mydate];
			return $rdate;
		}
		
		function loadNgayThangNam($date,$type){
			global $db;
			$rdate = "";
			if($type == 0){
				$dt = "day";
			}else if($type == 1){
				$dt = "month";
			}else{
				$dt = "year";
			}
			$rs = $db->query("SELECT ".$dt."('".$date."') as dat");
			$row = $db->fetch_array($rs);
			$rdate = $row[dat];
			return $rdate;
		}
		//funtion getIp
		function getIp() {
		if (isset($_SERVER)) {
			if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
				$realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
			} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
				$realip = $_SERVER['HTTP_CLIENT_IP'];
			} else {
				$realip = $_SERVER['REMOTE_ADDR'];
			}
		} else {
			if (getenv("HTTP_X_FORWARDED_FOR")) {
				$realip = getenv( "HTTP_X_FORWARDED_FOR");
			} elseif (getenv("HTTP_CLIENT_IP")) {
				$realip = getenv("HTTP_CLIENT_IP");
			} else {
				$realip = getenv("REMOTE_ADDR");
			}
		}
			return $realip;
		}
		
		
		function Redirect($Msg,$Link)
		{
			echo "<script language=\"javascript\">";
			if($Msg!="") echo "alert('$Msg');";
			if($Link!="") echo "window.location.href='$Link';";
			echo "</script>";
			break;
		}
		
		function flash($flash,$link,$width,$height){
			echo "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" id=\"ob1\" align=\"middle\" width=\"".$width."\" height=\"".$height."\">  
	<param name=\"wmode\" value=\"transparent\">       
	<param name=\"allowScriptAccess\" value=\"always\">          
	<param name=\"movie\" value=\"".$flash."\">          
	<param name=\"FlashVars\" value=\"link=".$link."\">           
	<param name=\"quality\" value=\"high\">           
	<embed src=\"".$flash."\" quality=\"high\" wmode=\"transparent\" name=\" helloWorld \" flashvars=\"link=".$link."\" allowscriptaccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" align=\"middle\" width=\"".$width."\" height=\"".$height."\">           
	</object>";
		}
		/*
		
		function DisplayFlash($flPath,$showWidth="",$showHeight="")
		{
			$imgsize = @getimagesize($flPath);
			$fWidth="100%";
			$fHeight="100%";
			if($showWidth!=""||$showHeight!="")
			{
				if($showWidth!="") $rWidth=$imgsize[0]/$showWidth; else $rWidth=1;
				if($showHeight!="") $rHeight=$imgsize[1]/$showHeight; else $rHeight=1;
				$rWidth>$rHeight?$ratioImg=$rWidth:$ratioImg=$rHeight;
				$fWidth=round($imgsize[0]/$ratioImg);
				$fHeight=round($imgsize[1]/$ratioImg);
			}elseif($showWidth==""&&$showHeight=="")
			{
				$fWidth=$imgsize[0];
				$fHeight=$imgsize[1];
			}
			$Temp="<script type=\"text/javascript\">AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','$fWidth','height','$fHeight','src','".SplitFileExt($flPath)."','quality','high','wmode','transparent','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','".SplitFileExt($flPath)."' );</script><noscript>
							<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=  \"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"$fWidth\" height=\"$fHeight\">
						  <param name=\"movie\" value=\"$flPath\" />
						  <param name=\"quality\" value=\"high\" />
						  <param name=\"wmode\" value=\"transparent\" />
						  <embed src=\"$flPath\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"$fWidth\" height=\"$fHeight\"></embed>
						</object></noscript>";
			return $Temp;
		}
		
		*/
		
		function DisplayImage($imPath,$showWidth="",$showHeight="",$imgBorder=0,$imgOption="")
		{
			$srcImg="";
			$imgsize = @getimagesize($imPath);
			if($imgsize[2]==1||$imgsize[2]==2||$imgsize[2]==6||$imgsize[2]==3)
			{
				$rWidth="";$rHeight="";
				$sWidthHeight="";
				if($showWidth!=""&&$showHeight!="")
				{
					$rWidth=$imgsize[0]/$showWidth;
					$rHeight=$imgsize[1]/$showHeight;
					$rWidth>$rHeight?$ratioImg=$rWidth:$ratioImg=$rHeight;
					$sWidthHeight=" width=\"".round($imgsize[0]/$ratioImg)."\" height=\"".round($imgsize[1]/$ratioImg)."\"";
				}else
				{
					if($showWidth=="") $sWidthHeight=" height=\"$showHeight\"";
					if($showHeight=="") $sWidthHeight=" width=\"$showWidth\"";
				}
				$srcImg="<img src=\"$imPath\" border=\"$imgBorder\"".$sWidthHeight." ".$imgOption.">";
			}
			return $srcImg;
		}
		
		function image($image,$link,$width,$height){
			echo "<a href=\"".$link."\"><img src=\"".$image."\" width=\"".$width."\" height=\"".$height."\" border=\"0\"></a>";
		}
		
		function showprice($ST)	// chuyen chuoi st sang cach hien thi gia ******* = *.***.***
		{
			$str= '';
				$j = 0;
				for($i = strlen($ST)-1; $i>=0; $i--){
					$j++;
					$tmp = substr($ST,$i,1);
					if(($j%3==0)&&($i>0)){
						$str = ".".$tmp.$str;
					}
					else{
						$str = $tmp.$str;
					}
				}
			return $str;
		}
		function SplitFileExt($str)
		{
			$temp=$str;
			$ipos=strpos($str,'.');
			if ($ipos>0) $temp=substr($str,0,$ipos);
			return $temp;
		}
		function getURL(){
			 $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
			 $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
			 $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
			 return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
 		} 
 
 		function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
?>